﻿//定时轮播类,构造函数
function RollBanner(){
this.index = 0;//当前播放广告索引
this.tmpZIndex = 0;
this.opa = 10;//每秒等差透明度
this.tmpOpa = 0;
this.relay = 6;//透明度达到100后,所等待的时间=this.relay*(setTimeout("RollBannerRun()",200);)
this.tmp_relay =this.relay;
this.banner = [];
this.visibleBanner = null;
this.MaxZIndex = 50;
this.preIndex = -1;
this.isPause = false;
this.bannerNav = null;
}
//添加图片方法 bannerID:放置图片的容器的ID
RollBanner.prototype.addBanner= function (bannerID){			
this.banner[this.banner.length] = {bannerID:bannerID};
}
//定时调用的函数
RollBanner.prototype.run = function(){
if(!this.visibleBanner){//首次运行，已有索引0显示，淡出效果开始索引为1
this.visibleBanner=document.getElementById(this.banner[this.index++].bannerID);
this.tmpOpa=100;
this.tmp_relay = 	this.relay;
}
if(this.tmpOpa!=100){//淡出效果				
this.tmpOpa+=this.opa
if(this.tmpOpa>100)this.tmpOpa=100;
if(navigator.userAgent.indexOf("Firefox")>0){//为ff浏览器 
this.visibleBanner.style.opacity=""+this.tmpOpa/100;//firefox使用											 
}else{
this.visibleBanner.style.filter="Alpha(opacity="+this.tmpOpa+")";//ie使用
}		 
}else if(this.tmpOpa==100&&this.tmp_relay!=0){
if(this.tmp_relay==this.relay&&!this.isPause){		  	
if(navigator.userAgent.indexOf("Firefox")>0){//为ff浏览器
if(this.preIndex!=-1)document.getElementById(this.banner[this.preIndex].bannerID).style.opacity="0";//firefox使用
this.preIndex=-1;
}else{
if(this.preIndex!=-1)document.getElementById(this.banner[this.preIndex].bannerID).style.filter="Alpha(opacity="+0+")";//ie使用
this.preIndex=-1;
}
if(this.index -1==-1)this.preIndex = this.banner.length-1;else this.preIndex = this.index -1;
}
if(!this.isPause)this.tmp_relay--;
}else if(this.tmpOpa==100&&this.tmp_relay==0){
this.tmpOpa =0;		  		  	
this.visibleBanner.style.zIndex=this.tmpZIndex;
this.turnActiveNav(this.index+1);
this.visibleBanner=document.getElementById(this.banner[this.index++].bannerID);		  			  	
this.visibleBanner.style.zIndex=this.MaxZIndex;
this.index=this.index%this.banner.length;//下一张	this.index索引 0...length-1	  	
this.tmp_relay = 	this.relay;
}
}

//停止播放
RollBanner.prototype.pause = function(){this.isPause = true;}

//继续播放
RollBanner.prototype.play = function(){this.isPause = false;}

//选择播放
RollBanner.prototype.selectRun = function(index){
this.turnActiveNav(index);
this.isPause = false;
this.index = index-1;
this.tmpOpa =80;		  		  	
this.visibleBanner.style.zIndex=this.tmpZIndex;
this.visibleBanner=document.getElementById(this.banner[this.index++].bannerID);		  			  	
this.visibleBanner.style.zIndex=this.MaxZIndex;
this.index=this.index%this.banner.length;//下一张	this.index索引 0...length-1	  	
this.tmp_relay = 	this.relay;
}

//继续播放
RollBanner.prototype.turnActiveNav = function(index){
if(!this.bannerNav)this.bannerNav = document.getElementById("slide_numbers");
this.bannerNav.className = "slide_number"+index;
}
//====================================================================================================
var indexRollBanner = new  RollBanner();				
function RollBannerRun(){
if(indexRollBanner.banner.length==0){
indexRollBanner.addBanner("stardoll_banner1");
indexRollBanner.addBanner("stardoll_banner2");
indexRollBanner.addBanner("stardoll_banner3");
indexRollBanner.addBanner("stardoll_banner4");
}
if(indexRollBanner.banner.length>0)indexRollBanner.run();
setTimeout("RollBannerRun()",200);
}